package com.dmm.user.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.dmm.user.entity.Association;
import com.dmm.user.entity.ExamineinfoVo;
import com.dmm.user.entity.Examineinfo;
import com.dmm.user.mapper.ExamineinfoMapper;
import com.dmm.user.service.AssociationService;
import com.dmm.user.service.ExamineinfoService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author com/dmm
 * @since 2023-04-07
 */
@Service
public class ExamineinfoServiceImpl extends ServiceImpl<ExamineinfoMapper, Examineinfo> implements ExamineinfoService {


    @Resource
    ExamineinfoMapper examineinfoMapper;

    @Resource
    AssociationService associationService;

    //更新number
    @Override
    public boolean updateNumber(String email) {

        boolean bool=examineinfoMapper.updateNumber(email);

        return false;
    }

    //绘图根据分数看人数
    @Override
    public Map<String, Object> getquantity() {

        Map<String, Object> map =new HashMap<>();
        List<ExamineinfoVo> list=examineinfoMapper.getquantity();
        System.out.println(list);
        int i=0;
        List list1=new ArrayList();
        List list2 =new ArrayList();
        int temp=0;
        if(list.isEmpty()){
            return null;
        }

        for(;i<12;i++){
            if(temp<list.size()){
                ExamineinfoVo examineinfoVo = list.get(temp);
                if(i==examineinfoVo.getResult()){
                    list1.add(examineinfoVo.getQuantity());
                    temp++;
                }else {
                    list1.add(0);
                }
            }else {
                list1.add(0);
            }


        }

        System.out.println(list1);
        map.put("ylist1",list1);
        return map;
    }

    //绘图根据分数看人数
    @Override
    public Map<String, Object> getavg() {

        ExamineinfoVo examineinfoVo=examineinfoMapper.getavg();
        Map<String,Object> map=new HashMap<>();
        List list=new ArrayList();
        list.add(examineinfoVo.getMax());
        list.add(examineinfoVo.getMin());
        list.add(examineinfoVo.getAvg());
        System.out.println(list);
        map.put("ydata",list);
        return map;
    }



    //获取可以被打分的用户
    @Override
    public List<String> getnames(String email) {

//        QueryWrapper<Examineinfo>queryWrapper1=new QueryWrapper<>();
//        queryWrapper1.ne("email",email);
//        List<Examineinfo> list1 = examineinfoMapper.selectList(queryWrapper1);
//
//
//        //查询关联表，查看可被打分的用户
//        QueryWrapper<Association> queryWrapper =new QueryWrapper<>();
//        queryWrapper.eq("end_email",email).select("start_email");
//        List<Association> list = associationService.list(queryWrapper);
//
//        System.out.println(list);

        List<String> list=examineinfoMapper.getnames(email);


        System.out.println(list);
        return list;
    }

    @Override
    public List<Examineinfo> getByIds(List<Long> list) {

        QueryWrapper<Examineinfo> queryWrapper=new QueryWrapper<>();
        queryWrapper.in("id",list).select("email");

        List<Examineinfo> list1 = examineinfoMapper.selectList(queryWrapper);

        List<String> list2=new ArrayList<>();
        for(Examineinfo info :list1){
            list2.add(info.getEmail());
        }

        QueryWrapper<Association> queryWrapper1=new QueryWrapper<>();
        queryWrapper1.in("start_email",list2);
        associationService.remove(queryWrapper1);


        return list1;
    }
}
